package com.lanou3g.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou3g.bean.Fix;
import com.lanou3g.mapper.FixMapper;
import com.lanou3g.service.FixService;
import com.lanou3g.util.Result;
@Service
public class FixServiceImpl implements FixService {

	@Autowired
	private FixMapper fixMapper;
	
	@Override
	public Result getFixs(Integer page, Integer limit) {
		List<Fix> fixs = fixMapper.getFixs();
		PageHelper.startPage(page, limit);
		PageInfo<Fix> pageInfo = new PageInfo<>(fixs);
		Result result = new Result(0,"获取维修记录成功!");
		result.setCount(pageInfo.getTotal());
		result.setData(pageInfo.getList());
		return result;
		
	}

	@Override
	public Result insetFix(Fix fix) {
		int rows = fixMapper.insetFix(fix);
		if(rows == 0) {
			//添加失败
			return new Result(1,"添加维修记录失败!");
		}else {
			return new Result(0,"添加维修记录成功!");
		}
	}

	@Override
	public Fix getFixById(Integer id) {
		return fixMapper.getFixById(id);
	}

	@Override
	public Result updateFix(Fix fix) {
		int rows = fixMapper.updateFix(fix);
		if(rows == 0) {
			//更新失败
			return new Result(1,"更新维修记录失败!");
		}else {
			return new Result(0,"更新维修记录成功!");
		}
	}

	@Override
	public Result deleteFix(Integer id) {
		int rows = fixMapper.deleteFix(id);
		if(rows == 0) {
			//删除失败
			return new Result(1,"删除维修记录失败!");
		}else {
			return new Result(0,"删除维修记录成功!");
		}
	}

}
